package main

import (

	"io/ioutil"
	"fmt"
	_ "unsafe"
	"strings"
)

func read_file(fname string) string {
	
	context, err := ioutil.ReadFile(fname)
	if (err != nil) {
		fmt.Println(err.Error())
		return ""
	}

	con_str := string(context)
	//fmt.Println(con_str)
	
	return con_str
}

func read_info(fname string) []VmData {

	ret := make([]VmData, 0)

	context, err := ioutil.ReadFile(fname)
	if (err != nil) {
		fmt.Println(err.Error())
		return ret
	}
	//fmt.Println(string(context))

	lines := strings.Split(string(context), "\n")
	//fmt.Println(len(lines))

    for _, line := range lines {

    	var one VmData
		fields := strings.Fields(line)
		one.nodeip = fields[0]
		one.node = fields[1]
		one.vmid = fields[2]

		for i := 0; i < len(fields)-3; i++ {

			one.vmp = append(one.vmp, fields[i+3])
		}
		one.vmp_num = len(fields) - 3
		ret = append(ret, one)
	}

	return ret
}
